#!/bin/sh
#
# This script is used for Darwin builds of the "release-dist" and "sdk-dist" targets. 
# The SDK files are arranged to make a root directory for PackageMaker.
#

AAFSDK="$1"
DIST_LIST="$2"
cd $AAFSDK
mkdir -p Dist/root
FileList=`grep -v \# $DIST_LIST`;
tar cf - ${FileList} | (cd Dist/root; tar xvf - )

# [HACK ALERT] 
# move dylibs from bin directory to lib directory
# 
cd Dist/root/bin
find . -type f -name "*.dylib" -print | cpio -pudm ../lib
cd ../../..
rm -f  Dist/root/bin/debug/*.dylib >/dev/null 2>&1
rmdir Dist/root/bin/debug >/dev/null 2>&1
rm -f  Dist/root/bin/*.dylib >/dev/null 2>&1
rmdir Dist/root/bin >/dev/null 2>&1

# set file permissions.
#
[ -d Dist/root/bin ] && chmod 755 Dist/root/bin
[ -d Dist/root/bin ] && chmod 755 Dist/root/bin/*
[ -d Dist/root/bin/debug ] && chmod 755 Dist/root/bin/debug
[ -d Dist/root/bin/debug ] && chmod 644 Dist/root/bin/debug/*
[ -d Dist/root/lib ] && chmod 755 Dist/root/lib
[ -d Dist/root/lib ] && chmod 644 Dist/root/lib/*
[ -d Dist/root/lib/debug ] && chmod 755 Dist/root/lib/debug
[ -d Dist/root/lib/debug ] && chmod 644 Dist/root/lib/debug/*
[ -d Dist/root/include ] && chmod 755 Dist/root/include
[ -d Dist/root/include ] && chmod 644 Dist/root/include/*

# set file ownership
#
[ $EUID -eq 0 ] && chown -R root:wheel Dist/root

# fix permissions - all directories should be executable
find Dist -type d -exec chmod +x \{\} \;
